<?php namespace sacvoyage\storage;

class QueryResultIterator implements \Iterator {

	public function __construct(&$result, $own=true) {
		$this->_result=&$result;
		$this->_own=$own;
	}

	public function __destruct() {
		if($this->_own) {
			$this->_result->free();
		}
	}

	public function rewind() {
		$this->_result->data_seek(0);
		$this->_currentKey=-1;
		$this->next();
	}

	public function key() {
		return $this->_currentKey;
	}

	public function current() {
		return $this->_currentRow;
	}
	
	public function next() {
		$this->_currentKey++;
		$this->_currentRow=$this->_result->fetch_assoc();
	}

	public function valid() {
		return $this->_currentRow!==null;
	}

	private $_result;
	private $_own;
	private $_currentRow;
	private $_currentKey;



}

?>
